<link rel="stylesheet" type="text/css" href="css/page.css"/>
<style type="text/css">
button{cursor: pointer;}
.wrap{width:80%;float:right;}
table{width:100%; line-height:23px;margin:10px 0; border-color:#d5dce2;}
th,td{ text-align:center; border-color:#d5dce2; line-height:30px;}
th{background:#f2f9ff;}
.pri{width:109px;height:22px;text-align:center;}
.fenyeiWrap{width:85%;}
#tplid{display:none;}
.addcp {background:url("http://www.12301.cc/images/btn23_two1.png") no-repeat scroll left top;display: inline-block;height: 23px;padding-left: 8px;text-decoration: none;float:right;}
.addcp span {background:url("http://www.12301.cc/images/btn23_two1.png") no-repeat scroll right top;color: #FFFFFF;display: inline-block;font-size: 12px;font-weight: bold;height: 23px;line-height: 23px;padding-right: 8px;}
.ty{background:#f0851d; border:1px solid #a9550f; height:25px;width:75px; color:#fff; padding-bottom:2px;  padding-bottom:0px\9; }
.tpllist{float:right;line-height: 25px;}
.txtlf{ text-align:left; padding-left:15px;}
.add,.rude {display: block;width: 10px;height: 11px;border: 1px solid;line-height: 9px;line-height: 8px\9;padding-right: 1px;font-size: 15px;
cursor: pointer;}
.add {
position: absolute;
right: -20px;
top: 9px;
}
.rude{
position: absolute;
right: 45px;
top: 9px;
}
#search{
	margin-left:200px;
}
</style>
<script type="text/javascript">

function changeRow(object){
	$(object).parent().parent().find(':text').attr('disabled',!object.checked);
}
function submitForm(){
	$("#save").submit();
}

$(document).ready(function(){
	$("#btn").click(function(){
				var did=$("#did").val();
				var prodname=$("#prodname").val();
				window.location="priceset_sale.html?did="+did+"&prodname="+prodname;
			})
})

function chPrice(object){
	var action = 0;
	if($(object).attr("class")=="add") action = 1;
	$(".pri").each(function(i,ele){
		if($(this).attr("disabled")!="disabled"){
			var price = $(this).val();
			var supply = Number($(this).parents().find(".supply").html());
			if(price=='') price = supply;
			if(action==1){// plus
				price = Number(price) + 1;
			}else{
				price = Number(price) - 1;
				// alert(price);
				if(price<supply) price = supply;
			}
			
			price = price.toFixed(2);
			$(this).val(price);
		}
	});

	
	
}

$(document).ready(function(){
        //全选
    $("#selectAllBtn").on("click",function(e){
        selectAll();
    })
    //全不选
    $("#cannelAllBtn").on("click",function(e){
        cancelAll();
    })
    var tt = 0;
    var oo = 0;
    $('.pri').on("keypress",function(){
        if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))
            this.value=tt;
        else
            tt=this.value;
        if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))
            oo=this.value
    })
    $('.pri').on("keyup",function(){
        if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))
            this.value=tt;
        else
            tt=this.value;
        if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))
            oo=this.value
    })
    $('.pri').on("blur",function(){
        if(!this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?|\.\d*?)?$/))
            this.value=this.oo;
        else{
            if(this.value.match(/^\.\d+$/))
                this.value=0+this.value;
            if(this.value.match(/^\.$/))
                this.value=0;
            oo=this.value
        }
    })
});

var selectAll = function(){
		$("#listTable").find(".tids").each(function(index,inp){
			$(inp).prop("checked","checked");
			$(this).parent().parent().find(':text').attr('disabled',!this.checked);
		})
	};
var cancelAll = function(){
		$("#listTable").find(".tids").each(function(index,inp){
			$(inp).prop("checked","");
			$(this).parent().parent().find(':text').attr('disabled',!this.checked);
		})
	};
</script>
<div class="wrap">
<h3 class="mc_title">
	<span class="mctit_1 mctit_3"><a href="priceset.html?did=<?=$did?>" class="mctit_2 mctit_4">自供应产品</a></span>
	<span class="mctit_1"><span class="mctit_2 ">转分销产品</span></span>
</h3></br>
<iframe name="ifr" style="display:none;"></iframe>
<form action="priceset_sale.php" target="ifr" id="save">
您正在为 <a style="font-size:14px;color:#2A98DA;margin-right:10px;"><?=$dname?></a> 配置转分销产品价格
<span style="font-size:14px;color:#2A98DA;" id="search">产品搜索: <input type="test" name="prodname" id="prodname"></span>
<input type="button" id="btn" style="width:60px" value="搜索">
<a class="addcp" onclick="submitForm()" href="javascript:void(0);"><span>保存价格</span></a>
<input type="hidden" name="did" id="did" value="<?=$did?>" />
<table border="1" id="listTable">
	<tr><th><a id="selectAllBtn" class="ckall" href="javascript:;">全选<a><a id="cannelAllBtn" class="reck" href="javascript:;">取消</a></th><th class="txtlf">产品名称</th><th>供应商</th><th>供货价</th><th>建议零售价</th><th>
	
	<div style="position:relative; display:inline-block;" >
		
		<span onclick="chPrice(this);" class="rude">-</span>
		<span class="p_t">结算价</span>
		<span onclick="chPrice(this);" class="add">+</span>
		
	</div>
	</th></tr>
	<? if(is_array($prod))
		foreach($prod as $key=>$p):?>
	<tr>
		<input type="hidden" name="src_pris[<?=$key?>]" value="<?=$p['fp']?>"/>
		<input type="hidden" name="src_pids[<?=$key?>]" value="<?=$p['id'];?>"/>
		<td><input type="checkbox" class="tids" name="pid[<?=$p['aid']?>]" <?=$p['checked']?> value="<?=$p['id']?>" onclick="changeRow(this);"/></td>
		<td class="txtlf"><?=$p['p_name']?></td>
		<td><?=$p['dname']?></td>
		<td class="supply"><?=$p['fp']?></td>
		<td class="supply"><?=$p['ls']?></td>
		<td><input class="pri" type="text" <?=$p['disabled']?> name="set_pris[<?=$key?>]" value="<?=$p['pri']?>"/></td>
	</tr>
	<?endforeach;
    //待删 原来是写在最后一个TD里面的 现在拉到外面去了 onkeypress="if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))this.o_value=this.value" onkeyup="if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))this.o_value=this.value" onblur="if(!this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?|\.\d*?)?$/))this.value=this.o_value;else{if(this.value.match(/^\.\d+$/))this.value=0+this.value;if(this.value.match(/^\.$/))this.value=0;this.o_value=this.value}"
    ?>
</table> 
<?page($total,$currentPage,$pageSize);?>

</form>
</div>